package com.eastcom.bm.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.eastcom.bm.atom.Atom_ActionEmailNotice;
import com.eastcom.bm.dao.IEmailNoticeDao;
import com.eastcom.common.db.JDBCTemplate;
import com.eastcom.common.db.ResultData;

public class EmailNoticeDao implements IEmailNoticeDao {

	public List<Atom_ActionEmailNotice> getAllEmailNotice() throws Exception {
		try{
			List<Atom_ActionEmailNotice> results=new ArrayList<Atom_ActionEmailNotice>();
			
			ResultData rd=JDBCTemplate.executeSQLQuery("select * from qa_emailnotice", JDBCTemplate.PROPAGATION_NEVER, false, false);
			while(rd.next()){
				Atom_ActionEmailNotice emailNotice=new Atom_ActionEmailNotice();
				
				emailNotice.setUuid(rd.getString("UUID"));
				emailNotice.setName(rd.getString("NAME"));
				emailNotice.setCName(rd.getString("CNAME"));
				emailNotice.setEmailAddress(rd.getString("EMAIL_ADDRESS"));
				emailNotice.setHost(rd.getString("HOST"));
				emailNotice.setPort(rd.getString("PORT"));
				emailNotice.setUserName(rd.getString("USERNAME"));
				emailNotice.setPassword(rd.getString("PASSWORD"));
				emailNotice.setSender(rd.getString("SENDER"));
				results.add(emailNotice);
			}

			return results;
		}
		catch(Exception e){
			throw e;
		}
	}

	public Atom_ActionEmailNotice findEmailNoticeByUUID(String uuid) throws Exception {
		try{
			Atom_ActionEmailNotice emailNotice=null;
			
			ResultData rd=JDBCTemplate.executeSQLQuery("select * from qa_emailnotice where uuid='"+uuid+"'", JDBCTemplate.PROPAGATION_NEVER, false, false);
			if(rd.next()){
				emailNotice=new Atom_ActionEmailNotice();
				
				emailNotice.setUuid(rd.getString("UUID"));
				emailNotice.setName(rd.getString("NAME"));
				emailNotice.setCName(rd.getString("CNAME"));
				emailNotice.setEmailAddress(rd.getString("EMAIL_ADDRESS"));
				emailNotice.setHost(rd.getString("HOST"));
				emailNotice.setPort(rd.getString("PORT"));
				emailNotice.setUserName(rd.getString("USERNAME"));
				emailNotice.setPassword(rd.getString("PASSWORD"));
				emailNotice.setSender(rd.getString("SENDER"));
			}

			return emailNotice;
		}
		catch(Exception e){
			throw e;
		}
	}

}
